package leetcode.editor.cn.q1_300.q50;

/**
 * @author qidi
 * @date 2021-12-09 12:15:49
 */
class Q0055_JumpGame {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public boolean canJump(int[] nums) {
            if (nums.length == 1) return true;
            int range = 0;
            for (int i = 0; i < nums.length - 1; i++) {
                if (nums[i] == 0 && range == i) {
                    return false;
                } else {
                    range = Math.max(range, i + nums[i]);
                }
            }
            return true;
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0055_JumpGame().new Solution();
        System.out.println(solution.canJump(new int[]{0, 1}));
        System.out.println(solution.canJump(new int[]{1, 0}));
        System.out.println(solution.canJump(new int[]{2, 0}));
        System.out.println(solution.canJump(new int[]{2, 3, 1, 1, 0}));
        System.out.println(solution.canJump(new int[]{3, 2, 1, 0, 4}));
    }
}